package Command;

import Server.Command;
import Server.cmdArguments;
import Command.HistoryTracker;

public class RedoCommand implements Command {
	private cmdArguments args;

	public RedoCommand() {}

	@Override
	public String execute() {
		String result = "Redo is not possible with the database.";
		if (!args.db) {
			HistoryTracker ht = HistoryTracker.getInstance();
			ht.pollLastCommand(); //removing self
			Command cmd = ht.pollLastUndo();

			if (cmd != null) {
				ht.addCommand(cmd); //adding to executed list			
				result = cmd.execute();
			} else {
				result = "Nothing to redo.";
			}
			
		}
		return result;
	}


	@Override
	public String undo() {
		return "Undo on a redo is not possible";
	}


	@Override
	public void setArgs(cmdArguments args) {
		this.args = args;		
	}

}
